package com.qdlc.p2p.biz.processor.task;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.qdlc.p2p.biz.processor.event.BorrowValueEvent;
import com.qdlc.p2p.common.constant.Summary;
import com.qdlc.p2p.common.constant.TradeCode;
import com.qdlc.p2p.common.core.queue.QueueHandlers;
import com.qdlc.p2p.common.util.DateUtil;
import com.qdlc.p2p.dal.dto.TppTradeLog;
import com.qdlc.p2p.dal.model.BorrowModel;

@Service
@Transactional
public class CollectionTradeNotifyVirtualTaskProcessor extends AbstractCollectionTradeNotifyBaseTaskProcessor {

	/**
	 * 代付成功是否需要处理
	 * @return
	 */
	@Override
	public boolean supprotTradeFinished(String serviceType) {
		return Summary.VIRTUAL_RED_ENVELOPE_EXCHAGE.getSummaryType().equals(serviceType);
	}
	
	/**
	 * 支持的外部业务码
	 * @return
	 */
	public TradeCode tradeCode(){
		return TradeCode.C1001;
	}
	
	/**
	 * 代收成功后需要处理的逻辑
	 * 代收成功后需要调用代付接口，由子类完成
	 */
	protected void doPay(TppTradeLog tppTradeLog){
		BorrowModel bm = new BorrowModel();
		long borrowId = tppTradeLog.getBorrowId();
		String tppUserCustId = tppTradeLog.getTppUserCustId();
		bm.setId(borrowId);
		bm.setBidNo(tppTradeLog.getOrderNo());
		bm.setTenderBilNo(tppTradeLog.getOrderNo());
		bm.setTenderBilDate(DateUtil.dateStr3(tppTradeLog.getTradeTime()));
		// borrowTender的account金额包含现金、红包、体验券
		bm.setMoney(tppTradeLog.getAmount());
		bm.setTppUserCustId(tppUserCustId);
		BorrowValueEvent borrowEvent = new BorrowValueEvent();
		borrowEvent.setBorrowModel(bm);
		borrowEvent.setTaskProcessorClass(VerifyFullSuccessTaskProcessor.class);
		QueueHandlers.put(borrowEvent);
	}
	
}
